<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection"
	content="telephone=no,email=no,date=no,address=no">
<title></title>
		<link rel="stylesheet" type="text/css" href="../css/aui.css"/>
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
<style>
			.aui-content-padded {
				padding: 0.75 rem;
				background-color: #ffffff;
				margin-top: 0.75 rem;
			}
</style>
</head>
<body>
	<header class="aui-bar aui-bar-nav aui-bar-warning" id="aui-header">
	<a class="aui-pull-left" onclick="window.history.back(-1);"> <span
		class="aui-iconfont aui-icon-left"></span>
	</a>
	<div class="aui-title">我的合同</div>
	<a class="aui-pull-right"> </a> </header>
	<div class="aui-searchbar" id="search">
		<div class="aui-searchbar-input aui-border-radius">
			<i class="aui-iconfont aui-icon-search"></i> <input type="search"
				placeholder="请输入合同编号" id="search-input">
			<div class="aui-searchbar-clear-btn">
				<i class="aui-iconfont aui-icon-close"></i>
			</div>
		</div>
		<div class="aui-searchbar-btn" tapmode>取消</div>
	</div>
	<section class="aui-content">
	<ul class="aui-list aui-media-list" id="nice-articles">
	</ul>
	</section>
	<section class="aui-content" id="list"></section>
	<div class="aui-toast" style="display:none;" id="loading">
		<div class="spinner aui-toast-content">
			<div class="spinner-container container1">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
			<div class="spinner-container container2">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
			<div class="spinner-container container3">
				<div class="circle1"></div>
				<div class="circle2"></div>
				<div class="circle3"></div>
				<div class="circle4"></div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.qrcode.min.js"></script>
<script type="text/javascript" src="../js/aui-dialog.js" ></script>
<script type="text/javascript" src="../js/common.js"></script>


<script type="text/javascript">
	var dialog = new auiDialog({});
	//得到选择机会信息的id
	var id = "${param.id}";
	//当前初始页
	var pageNumber = 1;
	//每页显示多少条
	var pageSize = 10;
	var countSize = 0;
	
	var id ="${sessionScope.loginCustomer.personLiable}";
	//初始方法
	$(function(){
		$("#nice-articles").html("");
		getPage(1, 99);
	});

	function getPage(pageNumber, pageSize) {
		$("#loading").show();
		var contractNum = $("#search-input").val();
		$.ajax({
			url : "${pageContext.request.contextPath}/appcrm/customerContractList.do?page=" + pageNumber + "&limit=" + pageSize + "&id=" + id + "&contractNum=" + contractNum,
			type : "POST",
			dataType : "json",
			success : function(data) {
				var rets = data;
				$("#loading").hide();
				if (rets.flag == 1 && rets.flag != "") {
					if (rets.data != "") {
						var da = rets.data;
						var customer = rets.customer;
						var html = "";
						for (var i = 0; i < da.length; i++) {
							html += '<li class="aui-list-item aui-list-item-middle" tapmode onclick="openDetailed(\'' + da[i].contractId + '\')"><div class="aui-media-list-item-inner"><div class="aui-list-item-inner aui-list-item-arrow"><div class="aui-list-item-text">';
							if (da[i].contractName != null && da[i].contractName != "") {
								html += '<div class="aui-list-item-title aui-font-size-14">' + da[i].contractName + '</div>';
							} else {
								html += '<div class="aui-list-item-title aui-font-size-14">滨海基金项目合同</div>';
							}
							if (da[i].createDate != null && da[i].createDate != "") {
								html += '<div class="aui-list-item-right">' + toDate(da[i].createDate) + '</div>'
							} else {
								html += '<div class="aui-list-item-right"></div>'
							}
							html += '</div><div class="aui-list-item-text">'
							if (da[i].contractNum != null && da[i].contractNum != "") {
								html += da[i].contractNum
							}
							html += '<div class="aui-list-item-right">'
							html += "</div></div></div></div></li>";
						}
						countSize = rets.total;
					//复制总记录数
					} else {
						$("#list").html("<div style='width:100%;text-align:center;color:#999;padding:10px 0;'>暂无数据！</div>");
					}
					$("#nice-articles").append(html);
					/* api.addEventListener({
						name : 'scrolltobottom',
						extra : {
							threshold : '100', //当事件为scrolltobottom时，设置距离底部多少距离时触发事件，默认值为0，数字类型
						},
					}, function(ret, err) {
						pageNumber++;
						if (pageNumber * 10 - 10 < countSize) {
							getPage(pageNumber, pageSize);
						} else {
							if (Math.ceil(countSize / 10) == pageNumber - 1) {
								$("#list").html("<div style='width:100%;text-align:center;color:#999;padding:20px 0;'>没有更多数据了！</div>");
							}
						}
					}); */
				} else {
					dialog.alert({
						msg : '暂无数据',
						buttons : [ '取消', '确定' ]
					}, function(ret) {
						console.log(ret)
					})
				}
			}
		});
	}


	//打开详细
	function openDetailed(id) {
		window.location.href="${pageContext.request.contextPath}/wap/public_work.do?path=frame_contract_detailed&id="+id;
 	} 
 	
 	function toDate(data) {
		var date = new Date(data);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		m = m < 10 ? '0' + m : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		return y + '-' + m + '-' + d;
	}
</script>
</html>